﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameCore;

namespace Interpreter.BuiltIns
{
	internal static class KeyCodeLookup
	{
		private static readonly Dictionary<Key, int> keyCodes = new Dictionary<Key, int>()
		{
			{ Key.Backspace, 8 },
			{ Key.Tab, 9 },
			{ Key.Enter, 13 },
			
			{ Key.LeftShift, 16 },
			{ Key.RightShift, 16 },
			{ Key.LeftCtrl, 17 },
			{ Key.RightCtrl, 17 },
			{ Key.LeftAlt, 18 },
			{ Key.RightAlt, 18 },
			{ Key.Pause, 19 },
			{ Key.CapsLock, 20 },

			{ Key.Escape, 27 },

			{ Key.Space, 32 },
			{ Key.PageUp, 33 },
			{ Key.PageDown, 34 },
			{ Key.End, 35 },
			{ Key.Home, 36 },
			{ Key.Left, 37 },
			{ Key.Up, 38 },
			{ Key.Right, 39 },
			{ Key.Down, 40 },

			{ Key.Insert, 45 },
			{ Key.Delete, 46 },

			{ Key.Num0, 48 },
			{ Key.Num1, 49 },
			{ Key.Num2, 50 },
			{ Key.Num3, 51 },
			{ Key.Num4, 52 },
			{ Key.Num5, 53 },
			{ Key.Num6, 54 },
			{ Key.Num7, 55 },
			{ Key.Num8, 56 },
			{ Key.Num9, 57 },

			{ Key.A, 65 },
			{ Key.B, 66 },
			{ Key.C, 67 },
			{ Key.D, 68 },
			{ Key.E, 69 },
			{ Key.F, 70 },
			{ Key.G, 71 },
			{ Key.H, 72 },
			{ Key.I, 73 },
			{ Key.J, 74 },
			{ Key.K, 75 },
			{ Key.L, 76 },
			{ Key.M, 77 },
			{ Key.N, 78 },
			{ Key.O, 79 },
			{ Key.P, 80 },
			{ Key.Q, 81 },
			{ Key.R, 82 },
			{ Key.S, 83 },
			{ Key.T, 84 },
			{ Key.U, 85 },
			{ Key.V, 86 },
			{ Key.W, 87 },
			{ Key.X, 88 },
			{ Key.Y, 89 },
			{ Key.Z, 90 },
			
			{ Key.NumPad0, 96 },
			{ Key.NumPad1, 97 },
			{ Key.NumPad2, 98 },
			{ Key.NumPad3, 99 },
			{ Key.NumPad4, 100 },
			{ Key.NumPad5, 101 },
			{ Key.NumPad6, 102 },
			{ Key.NumPad7, 103 },
			{ Key.NumPad8, 104 },
			{ Key.NumPad9, 105 },

			{ Key.NumPadMultiply, 106 },
			{ Key.NumPadAdd, 107 },

			{ Key.NumPadSubtract, 109 },
			{ Key.NumPadDecimal, 110 },
			{ Key.NumPadDivide, 111 },
			{ Key.F1, 112 },
			{ Key.F2, 113 },
			{ Key.F3, 114 },
			{ Key.F4, 115 },
			{ Key.F5, 116 },
			{ Key.F6, 117 },
			{ Key.F7, 118 },
			{ Key.F8, 119 },
			{ Key.F9, 120 },
			{ Key.F10, 121 },
			{ Key.F11, 122 },
			{ Key.F12, 123 },

			{ Key.NumLock, 144 },
			{ Key.ScrollLock, 145 },

			{ Key.Semicolon, 186 },
			{ Key.Equals, 187 },
			{ Key.Comma, 188 },
			{ Key.Hyphen, 189 },
			{ Key.Period, 190 },
			{ Key.Slash, 191 },
			{ Key.Backtick, 192 },

			{ Key.OpenBracket, 219 },
			{ Key.Backslash, 220 },
			{ Key.CloseBracket, 221 },
			{ Key.Apostrophe, 222 },
		};

		public static int GetKeyCode(Key key)
		{
			if (keyCodes.ContainsKey(key))
			{
				return keyCodes[key];
			}
			return 0;
		}
	}
}
